Course: Internet Application Development
Lab: 9B
Technology: ASP.NET Web Forms using VB.NET
Create a web form containing a ListBox with programming language options. When a user selects a language, display relevant information below using AutoPostBack and event handling.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Problem_1.aspx.vb" Inherits="Problem_1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Programming Language Info</title> </head> <body> <form id="form1" runat="server"> <div> <h3>Select a Programming Language:</h3> <asp:ListBox ID="ListBoxLanguages" runat="server" AutoPostBack="True" SelectionMode="Single" OnSelectedIndexChanged="ListBoxLanguages_SelectedIndexChanged"> <asp:ListItem>Java</asp:ListItem> <asp:ListItem>JavaScript</asp:ListItem> <asp:ListItem>C#</asp:ListItem> <asp:ListItem>C++</asp:ListItem> <asp:ListItem>C</asp:ListItem> <asp:ListItem>Python</asp:ListItem> <asp:ListItem>SQL</asp:ListItem> <asp:ListItem>HTML</asp:ListItem> <asp:ListItem>CSS</asp:ListItem> <asp:ListItem>PHP</asp:ListItem> </asp:ListBox> <br /><br /> <asp:Label ID="LabelInfo" runat="server" Font-Bold="True" ForeColor="Blue" /> </div> </form> </body> </html>
Partial Class Problem_1 Inherits System.Web.UI.Page Protected Sub ListBoxLanguages_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBoxLanguages.SelectedIndexChanged Dim selectedLanguage As String = ListBoxLanguages.SelectedItem.Text Dim message As String = "" Select Case selectedLanguage Case "Java" message = "Java is a versatile and widely-used object-oriented programming language." Case "JavaScript" message = "JavaScript is a scripting language primarily used for creating interactive web pages." Case "C#" message = "C# is a modern, object-oriented programming language developed by Microsoft." Case "C++" message = "C++ is an extension of C that includes object-oriented features." Case "C" message = "C is a general-purpose, procedural programming language." Case "Python" message = "Python is a high-level, interpreted language known for its simplicity and readability." Case "SQL" message = "SQL is a domain-specific language used for managing and querying relational databases." Case "HTML" message = "HTML is the standard markup language for creating web pages." Case "CSS" message = "CSS is used to style and layout web pages." Case "PHP" message = "PHP is a server-side scripting language designed for web development." Case Else message = "Please select a language." End Select LabelInfo.Text = message End Sub End Class
Create a dynamic table using dropdowns to choose number of rows and columns (1-10). The first column should contain dropdowns with language options. The last row should include radio button lists in each cell. Apply a border and background color to last row.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Problem_2.aspx.vb" Inherits="Problem_2" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Dynamic Table Generator</title> <style> table, td { border: 2px solid red; border-collapse: collapse; padding: 8px; } .last-row { background-color: grey; } </style> </head> <body> <form id="form1" runat="server"> <asp:DropDownList ID="DropDownRows" runat="server"></asp:DropDownList> <asp:DropDownList ID="DropDownCols" runat="server"></asp:DropDownList> <asp:Button ID="btnGenerate" runat="server" Text="Generate Table" OnClick="btnGenerate_Click" /> <br /><br /> <asp:PlaceHolder ID="PlaceHolderTable" runat="server" /> </form> </body> </html>
Partial Class Problem_2 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then ' Fill row and column dropdowns with values 1 to 10 For i As Integer = 1 To 10 DropDownRows.Items.Add(i.ToString()) DropDownCols.Items.Add(i.ToString()) Next End If End Sub Protected Sub btnGenerate_Click(sender As Object, e As EventArgs) Dim rows As Integer = Integer.Parse(DropDownRows.SelectedValue) Dim cols As Integer = Integer.Parse(DropDownCols.SelectedValue) Dim table As New Table() table.BorderColor = Drawing.Color.Red table.BorderWidth = 2 For i As Integer = 1 To rows Dim row As New TableRow() For j As Integer = 1 To cols Dim cell As New TableCell() ' First column of each row: dropdown list If j = 1 Then Dim langDDL As New DropDownList() langDDL.Items.Add("Urdu") langDDL.Items.Add("English") langDDL.Items.Add("Arabic") langDDL.Items.Add("Chinese") cell.Controls.Add(langDDL) Else cell.Text = "{" & i.ToString() & ", " & j.ToString() & "}" End If ' Last row: radio button list in every cell If i = rows Then cell.CssClass = "last-row" Dim rbl As New RadioButtonList() rbl.RepeatDirection = RepeatDirection.Horizontal rbl.Items.Add("1") rbl.Items.Add("2") rbl.Items.Add("3") rbl.Items.Add("4") cell.Controls.Clear() cell.Controls.Add(rbl) End If row.Cells.Add(cell) Next table.Rows.Add(row) Next PlaceHolderTable.Controls.Clear() PlaceHolderTable.Controls.Add(table) End Sub End Class